﻿/**  版本信息模板在安装目录下，可自行修改。
* t_video_study.cs
*
* 功 能： N/A
* 类 名： t_video_study
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2014/11/29 20:35:40   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace XinKuaiJi.DAL
{
	/// <summary>
	/// 数据访问类:t_video_study
	/// </summary>
	public partial class t_video_study
	{
		public t_video_study()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("id", "t_video_study"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from t_video_study");
			strSql.Append(" where id=@id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int32,11)			};
			parameters[0].Value = id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(XinKuaiJi.Model.t_video_study model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into t_video_study(");
			strSql.Append("id,user_id,video_id,last_time,first_time,history_time,c1,c2,c3)");
			strSql.Append(" values (");
			strSql.Append("@id,@user_id,@video_id,@last_time,@first_time,@history_time,@c1,@c2,@c3)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int32,11),
					new MySqlParameter("@user_id", MySqlDbType.Int64,64),
					new MySqlParameter("@video_id", MySqlDbType.VarChar,15),
					new MySqlParameter("@last_time", MySqlDbType.DateTime),
					new MySqlParameter("@first_time", MySqlDbType.DateTime),
					new MySqlParameter("@history_time", MySqlDbType.Int32,11),
					new MySqlParameter("@c1", MySqlDbType.VarChar,200),
					new MySqlParameter("@c2", MySqlDbType.VarChar,200),
					new MySqlParameter("@c3", MySqlDbType.VarChar,200)};
			parameters[0].Value = model.id;
			parameters[1].Value = model.user_id;
			parameters[2].Value = model.video_id;
			parameters[3].Value = model.last_time;
			parameters[4].Value = model.first_time;
			parameters[5].Value = model.history_time;
			parameters[6].Value = model.c1;
			parameters[7].Value = model.c2;
			parameters[8].Value = model.c3;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(XinKuaiJi.Model.t_video_study model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update t_video_study set ");
			strSql.Append("user_id=@user_id,");
			strSql.Append("video_id=@video_id,");
			strSql.Append("last_time=@last_time,");
			strSql.Append("first_time=@first_time,");
			strSql.Append("history_time=@history_time,");
			strSql.Append("c1=@c1,");
			strSql.Append("c2=@c2,");
			strSql.Append("c3=@c3");
			strSql.Append(" where id=@id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@user_id", MySqlDbType.Int64,64),
					new MySqlParameter("@video_id", MySqlDbType.VarChar,15),
					new MySqlParameter("@last_time", MySqlDbType.DateTime),
					new MySqlParameter("@first_time", MySqlDbType.DateTime),
					new MySqlParameter("@history_time", MySqlDbType.Int32,11),
					new MySqlParameter("@c1", MySqlDbType.VarChar,200),
					new MySqlParameter("@c2", MySqlDbType.VarChar,200),
					new MySqlParameter("@c3", MySqlDbType.VarChar,200),
					new MySqlParameter("@id", MySqlDbType.Int32,11)};
			parameters[0].Value = model.user_id;
			parameters[1].Value = model.video_id;
			parameters[2].Value = model.last_time;
			parameters[3].Value = model.first_time;
			parameters[4].Value = model.history_time;
			parameters[5].Value = model.c1;
			parameters[6].Value = model.c2;
			parameters[7].Value = model.c3;
			parameters[8].Value = model.id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from t_video_study ");
			strSql.Append(" where id=@id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int32,11)			};
			parameters[0].Value = id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from t_video_study ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XinKuaiJi.Model.t_video_study GetModel(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,user_id,video_id,last_time,first_time,history_time,c1,c2,c3 from t_video_study ");
			strSql.Append(" where id=@id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int32,11)			};
			parameters[0].Value = id;

			XinKuaiJi.Model.t_video_study model=new XinKuaiJi.Model.t_video_study();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XinKuaiJi.Model.t_video_study DataRowToModel(DataRow row)
		{
			XinKuaiJi.Model.t_video_study model=new XinKuaiJi.Model.t_video_study();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=int.Parse(row["id"].ToString());
				}
				if(row["user_id"]!=null && row["user_id"].ToString()!="")
				{
					model.user_id=long.Parse(row["user_id"].ToString());
				}
				if(row["video_id"]!=null)
				{
					model.video_id=row["video_id"].ToString();
				}
				if(row["last_time"]!=null && row["last_time"].ToString()!="")
				{
					model.last_time=DateTime.Parse(row["last_time"].ToString());
				}
				if(row["first_time"]!=null && row["first_time"].ToString()!="")
				{
					model.first_time=DateTime.Parse(row["first_time"].ToString());
				}
				if(row["history_time"]!=null && row["history_time"].ToString()!="")
				{
					model.history_time=int.Parse(row["history_time"].ToString());
				}
				if(row["c1"]!=null)
				{
					model.c1=row["c1"].ToString();
				}
				if(row["c2"]!=null)
				{
					model.c2=row["c2"].ToString();
				}
				if(row["c3"]!=null)
				{
					model.c3=row["c3"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,user_id,video_id,last_time,first_time,history_time,c1,c2,c3 ");
			strSql.Append(" FROM t_video_study ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM t_video_study ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from t_video_study T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "t_video_study";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

